package com.meta.md.controller;


import com.meta.md.service.MdService;
import com.meta.nd.vo.*;
import com.meta.util.ExceptionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController	
public class MdController {

	@Resource
	MdService mdService;
	
	
	@RequestMapping(value="/md/getMd", method = { RequestMethod.POST })
	public ReturnMessage<Nv> getMd (@RequestBody RequestMessage<String> requestMessage) {
		String mdCode = requestMessage.getValue();
		try {
			Nv nv = mdService.getMd(mdCode);
			return new ReturnMessage<Nv>(nv,true);
		}catch (Exception e ){
			log.error(e.getMessage(),e);
			return ExceptionUtils.buildReturnMessage(e);
		}
	}

	@RequestMapping(value="/md/getMvs")
	public ReturnMessage<List<Nv>> getMvs (@RequestBody RequestMessage<String> requestMessage){
		String mdCode = requestMessage.getValue();
		try {
			Nv nv = mdService.getMd(mdCode);
			return new ReturnMessage<List<Nv>>(nv.getSingleNvs(),true);
		}catch (Exception e ){
			log.error(e.getMessage(),e);
			return ExceptionUtils.buildReturnMessage(e);
		}
	}


	@RequestMapping(value="/md/getMv")
	public ReturnMessage<Nv> getMv (@RequestBody RequestMessage2<String,String> requestMessage) {
		String mdCode = requestMessage.getValue1();
		String mvCode =requestMessage.getValue2();
		try {
			Nv nv = mdService.getMv(mdCode,mvCode);
			return new ReturnMessage<Nv>(nv,true);
		}catch (Exception e ){
			log.error(e.getMessage(),e);
			return ExceptionUtils.buildReturnMessage(e);
		}
	}




}


